package card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:岁亮亮
 * Date:2024-01-18
 * TIME:10:20
 */
public class Cardplay {
    private static final String[] suit={"♥","♠","♦","♣"};
    public List<Card> buycard(){
        List<Card> cardslist=new ArrayList<>();

        for (int i = 0; i <4 ; i++) {
            for (int j = 1; j <14 ; j++) {
                Card card=new Card(suit[i],j);
                cardslist .add(card);
            }
        }
        return cardslist;
    }

    public void shullfeCard(List<Card> cardList){
        Random random=new Random();
        for (int i = cardList.size() -1; i >0 ; i--) {
            int indexof=random.nextInt(i);
            swap(cardList,i,indexof);
        }

    }
    //交换 i 与随机数indexof  的牌
    public void swap(List<Card> cardlist ,int i,int indexof){
        Card tmp=cardlist.get(i);//tmp==a;
        cardlist.set(i,cardlist.get(indexof )) ;//a==b;
        cardlist.set(indexof ,tmp);//b=tmp;
    }

    public void getCard(List<Card> cardList ){
        List<Card> people1=new ArrayList<>();
        List<Card> people2=new ArrayList<>();
        List<Card> people3=new ArrayList<>();
        //三个人玩  一轮一张 16轮 剩下4张地主牌
        List<List<Card>> peoples=new ArrayList<>();
        peoples.add(people1);
        peoples.add(people2);
        peoples.add(people3);
        System.out.println("洗完的牌如下");
        System.out.println(cardList);

        for (int i = 0; i < 16; i++) {
            for (int j = 0; j < 3; j++) {
                Card card=cardList.remove(0);
                peoples.get(j).add(card);
            }
        }
        System.out.println("第一个人的牌如下");
        System.out.println(people1);
        System.out.println("第二个人的牌如下");
        System.out.println(people2 );
        System.out.println("第三个人的牌如下");
        System.out.println(people3 );
        System.out.println("剩下地主的四张牌如下");
        System.out.println(cardList);


    }


}
